package com.yiwyn.service;

import com.yiwyn.handle.ConsumerHandle;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import sun.java2d.pipe.SpanIterator;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@Service
@Log4j2
public class ConsumerService {


    @Resource
    private ConsumerHandle consumerHandle;

    public String test() throws ExecutionException, InterruptedException {

        CompletableFuture<String>[] futures = new CompletableFuture[3];
        for (int i = 0; i < 3; i++) {
            futures[i] = consumerHandle.futureHandle();
        }
        CompletableFuture.allOf(futures).join();

        System.out.println("执行主线程");

        for (CompletableFuture<String> future : futures) {
            System.out.println(future.get());
        }

        return "success";
    }


}
